﻿using AEFunction;
using CommonFunction;
using ESRI.ArcGIS.Carto;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace AETools.UI
{
    public partial class SelectLayers : Form
    {
        public ILayer[] Layers;
        public string SavePath;
        public SelectLayers(ILayer[] layers)
        {
            InitializeComponent();
            foreach (ILayer l in layers)
            {
                listBox1.Items.Add((object)l.Name);
            }
            Layers = layers;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            listBox2.Items.AddRange(listBox1.Items);
            listBox1.Items.Clear();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Xml坐标文件(*.xml)|*.xml";
            sfd.Title = "选择shp文件保存路径";
            if (sfd.ShowDialog() != DialogResult.OK)
                return;
            textBox1.Text = sfd.FileName;
            SavePath = textBox1.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("未选择文件保存路径！!！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            List<ILayer> ls = new List<ILayer>();
            foreach (var item in listBox2.Items)
            {

                ls.Add(ArcEngineFunction.GetLayerByName(Layers, item.ToString()));
            }
            Layers = ls.ToArray();
            ls.Clear();
            this.DialogResult = DialogResult.OK;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void button4_Click_1(object sender, EventArgs e)
        {
            List<object> selectedItems = new List<object>();

            selectedItems = Function.GetSelectItems(listBox1);
            listBox2.Items.AddRange(selectedItems.ToArray());
            Function.RemoveSelectItems(listBox1, selectedItems);
            selectedItems.Clear();
        }

        private void button5_Click_1(object sender, EventArgs e)
        {
            listBox1.Items.AddRange(listBox2.Items);
            listBox2.Items.Clear();
        }

        private void button6_Click_1(object sender, EventArgs e)
        {
            List<object> selectedItems = new List<object>();
            selectedItems = Function.GetSelectItems(listBox2);
            listBox1.Items.AddRange(selectedItems.ToArray());
            Function.RemoveSelectItems(listBox2, selectedItems);
            selectedItems.Clear();
        }

    }
}
